package Demo3;

import java.util.Objects;

public class Student implements Cloneable{
    public String name;
    public int age;
    public Inner inner;

    public Student(String name, int age,Inner inner) {
        this.name = name;
        this.age = age;
        this.inner = inner;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", inner=" + inner.classRoom +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //深拷贝的实现
        Student temp = (Student) super.clone();
        Inner inner1 = (Inner) temp.inner.clone();
        temp.inner = inner1;
        return temp;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name) && Objects.equals(inner, student.inner);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, inner);
    }
}
